// 导入封装好的接口
const http = require('../../api/http');
const request = require('../../request/index');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: request.oss_url,
    deviceId: null,
    returnTime: '',
    borrowRemark: '',
    show: false,
  },

  onLoad(options) {
    const { deviceId,deviceStatus} = options;
    console.log(options,"options");

    this.setData({
      deviceId,
      deviceStatus
    })
  },

  onDisplay() {
    this.setData({ show: true });
  },
  onClose() {
    this.setData({ show: false });
  },
  formatDate(returnTime) {
    returnTime = new Date(returnTime);
    const year = returnTime.getFullYear();
    const month = String(returnTime.getMonth() + 1).padStart(2, '0');
    const day = String(returnTime.getDate()).padStart(2, '0');
    return `${year}-${month}-${day}`;
  },
  onConfirm(event) {
    this.setData({
      show: false,
      returnTime: this.formatDate(event.detail),
    });
  },
  onSubmit(){
    console.log(this.data);
    // const {deviceId, borrowRemark, returnTime} = this.data

    http.borrowApplication(this.data).then((res) => {
      console.log(res,"res")
      if(res.code == 200){
        wx.showToast({
          title: '申请成功',
          icon: 'success',
          duration: 500
        })
        this.borrowApplicationSuccess()
      }
    })
  },
  borrowApplicationSuccess(){
    //跳转列表
    wx.navigateTo({
      url: '/pages/equipList/index'
    })
  },
})